<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\common\controller\Admin;
use think\Request;

class Menu extends Admin
{
    protected $popup_size = ['width'=>'500px','height'=>'600px'];
    protected $with = ['file_id_image','parent'];
    public function initialize()
    {
        $this->menu_input = [
            'all' => [
                ['type' => 'select', 'name' => '所属栏目', 'key' => 'parent_id',
                    'select' => [
                    'table' => 'Menu'
                    ],
                    'dg' => 1
                ],
                ['type' => 'text', 'name' => '标题', 'key' => 'title','verify'=>'required'],
                ['type' => 'text', 'name' => '副标题', 'key' => 'ex_title'],
                ['type' => 'tags', 'name' => '标签', 'key' => 'tags'],
                ['type' => 'image', 'name' => '图标', 'key' => 'file_id'],
                ['type' => 'content', 'name' => '内容', 'key' => 'content'],
            ],
            'add' => [

            ],
            'upload' => [

            ],
        ];
        if(input('parent')){
            $this->menu_input['all'][0]['select']['where'] = ['key'=>'parent_id','value'=>input('parent')];
        }
        parent::initialize(); // TODO: Change the autogenerated stub
    }
    public function table_mage(&$data = [])
    {
        $data = [
            ['field' => 'title', 'title' => '栏目名称'],
            ['field' => 'parent_title', 'title' => '父级栏目'],
            ['field' => 'create_time', 'title' => '添加时间'],
            ['field' => 'update_time', 'title' => '修改时间'],
            ['title' => '操作', 'templet' => '#list_setting']
        ];
        return parent::table_mage($data); // TODO: Change the autogenerated stub
    }
    public function index_handle(&$data)
    {
        $res = $data['data'];
        $res = array_map(function($v){
            if(!empty($v['parent'])){
                $v['parent_title'] = $v['parent']['title'];
            }else{
                $v['parent_title'] = '无';
            }
            return $v;
        },$res);
        $data['data'] = $res;
        return parent::index_handle($data); // TODO: Change the autogenerated stub
    }
}
